<?php
namespace app\admin\controller;
use app\common\controller\Admin;

class Pets extends Admin {
    public function index()
    {
		$order = "id desc";
		//获取列表数据
		$list = model('Pets')->order($order)->paginate(10);

		// 记录当前列表页的cookie
		Cookie('__forward__', $_SERVER['REQUEST_URI']);
		$data = array(
			'list' => $list,
			'page' => $list->render(),
		);
		$this->assign($data);
		$this->setMeta('宠物列表');
		return $this->fetch();
    }

    public function audit($id = 0) {
        $result = model('Pets')->save(['status' => 1], ['id' => $id]);
        if($result) {
            $this->success('操作通过');
        }else{
            $this->error('操作失败');
        }
    }

    public function delete($id = 0) {
		if (!$id) {
			return $this->error("非法操作！", '');
		}
		$map['id'] = array('IN', $id);
		$result    = db('Pets')->where($map)->delete();
		if ($result) {
			action_log('delete_action', 'Pets', $id, session('user_auth.uid'));
			return $this->success('删除成功！');
		} else {
			return $this->error('删除失败！');
		}
    }
}
